package models;

import views.TurretInterfaceView;
import controllers.*;

public class Servo {

	public int currentPosition = 3456;
	private Thread moveServoThread;

	public Servo() {
		byte[] bytes = ByteHandler.createServoBytes(3456);
		SerialSpeaker.writeToSerialPort(bytes);
	}

	public void setPosition(int position) throws InterruptedException {
		if(position > 4606 || position < 2306) {
			System.err.println("Illegal servo position ordered!");
		} else {
			moveServoThread = new Thread(new MoveServoThread(ByteHandler.createServoBytes(position)));
			moveServoThread.start();
			currentPosition  = position;
			TurretInterfaceView.servoPositionLabel.setText(Integer.toString(currentPosition));
		}
	}

}
